/**
 * Created by yunpeng on 2015/6/11.
 */
var xlsx = require("node-xlsx");
var Table = require('../utils/Table').Table;

var flag = true;
var list = xlsx.parse('priceline.xlsx')[0].data;
list.splice(0, 1);

new Table().getConnection(function (connection) {
    connection.beginTransaction(function (err) {
        if (err) { //throw err;
            callback(false);
        }
        list.forEach(function (column, index) {
            console.log(column + '  ' + index);

            connection.query('INSERT INTO lineprice SET ?', {startstation: column[0],endstation:column[1],price:column[2],userid:0,createtime:new Date()}, function (err, result) {
                if (err) {
                    flag=false;
                    connection.rollback(function () {
                        //throw err;
                        /*callback(false);*/
                    });
                }
            });
        });

        console.log('------------------');
        if(flag){
            connection.commit(function (err) {
                if (err) {
                    connection.rollback(function () {
                        //throw err;
                        callback(false);
                    });
                } else {
                    connection.release(); //release
                    console.log('当前~~~');
                }
            });
        }

    });

});


